package com.hd.trans.utils;

import com.hd.trans.files.bean.MimeType;

import java.util.List;

/**
 * @author qianjujun
 * @email qianjujun@163.com
 * @createTime 2020/11/10 15:45
 * @describe
 */
public class SelectionUtil {
    public static void handlerInclude(StringBuilder selection, List<MimeType> mimeTypeList, String symbol, String condition) {
        if (mimeTypeList == null || mimeTypeList.isEmpty()) {
            return;
        }
        selection.append(" AND (");
        MimeType mimeType;
        for (int i = 0; i < mimeTypeList.size(); i++) {
            mimeType = mimeTypeList.get(i);
            selection.append("mime_type ").append(symbol).append(" '");
            selection.append(mimeType.getMimeTypeName());
            selection.append("'");
            if (i < mimeTypeList.size() - 1) {
                selection.append(" ").append(condition).append(" ");
            }
        }
        selection.append(")");
    }

    public static void handlerInclude(StringBuilder selection, List<MimeType> mimeTypeList) {
        handlerInclude(selection, mimeTypeList, "=", "OR");
    }

    public static void handlerExclude(StringBuilder selection, List<MimeType> mimeTypeList) {
        handlerInclude(selection, mimeTypeList, "!=", "AND");
    }

}
